﻿/**
* Title:"项目";
*
* Description:
*        功能：
*
* Author:Tongwel
*
* Date:2018.6
*
* Modify:
*/
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Linq;

public class PackProxy : BaseProxy<PackModel>
{
    #region 单例
    private static PackProxy _instance;
    public static PackProxy Instance
    {
        get {
            if (_instance==null)
            {
                _instance = new PackProxy();
            }
            return _instance;
        }
    }
    #endregion

    public PackProxy() : base()
    {
        //实例化背包栏
        for (int i = 0; i < 15; i++)
        {
            this.AddModel2List(new PackModel(i));
        }
    }

    //获取一个空的背包
    public PackModel GetEmptyModel()
    {
        return this.modelList.FirstOrDefault(a => a.GoodID == 0);
    }

    //判断背包是否满了
    internal bool IsFull()
    {
        //查看有多少个goodID是0的 O的话就 +1
        int count = this.modelList.Count(a => a.GoodID == 0);
        if (count == 0)
        {
            return true;
        }
        else
        {
            return false;
        }        
    }

    //判断背包是否有这个good model
    internal bool TryGetGoodModel(int goodID,out PackModel model)
    {
        model = null;
        //判断加赋值
        model = this.modelList.FirstOrDefault(a => a.GoodID == goodID);
        if (model == null)
        {
            return false;
        }
        else
        {
            return true;
        }
    }
}
